import React, { Component } from 'react';
import { Button, Form, Input, Space,InputNumber} from "antd";
import TheQuill from "../../../../components/TheQuill";
import TheUpload from '../../../../components/TheUpload';
class Add extends Component {
    constructor(props) {
        super(props)
        this.state = {
            fileList: null,
            content:''
        }
    }
    componentDidMount() {
        // if (this.props.data) {
        //     this.formRef.setFieldsValue({ ...this.props.data })
        //     this.setNewsContent(this.props.data.aboutUsDetails)
        //     const fileList = [
        //         {
        //             uid: '-1',
        //             name: 'image.png',
        //             status: 'done',
        //             url: this.props.data.aboutUsDetailsImage,
        //         },
        //     ]
        //     this.setState({
        //         fileList
        //     })
        // }
        // console.log(this.state.fileList)
    }

    /**
     * @desc 设置新闻内容表单默认值
     * */
    setNewsContent = (data) => {
        this.formRef.setFieldsValue({ content: data })
    }

    //图片上传回调
    getDetailsFileResult = value => {
    
        if (value.length && value[0] && value[0].response) {
            this.formRef.setFieldsValue({
                preImgUrl:value[0].response.data
            })
        }else{
            this.formRef.setFieldsValue({
                preImgUrl:''
            })
        }
    }
    render() {
        const { btnLoading, dialogCancel, onFinish, } = this.props
        const {fileList,content} = this.state
        return <Form
            ref={ref => {
                this.formRef = ref
            }}
            onFinish={onFinish}
        >
            <Form.Item name={'title'} rules={[{ required: true, message: '请输入标题' }]} label={'标题'}>
               <Input maxLength={50} />

            </Form.Item>
            <Form.Item label={'自定义ID'} rules={[{ required: true, message: '请输入ID' }]} name={'definingId'} >
                <Input />
            </Form.Item>
            <Form.Item label={'封面图片'} name={'preImgUrl'} >
                <TheUpload fileList={fileList} maxSize={10} len={1} getFileResult={this.getDetailsFileResult} />    
            </Form.Item>
            <Form.Item label={'排序'} name={'articleSort'} >
                <InputNumber style={{width:300}}></InputNumber>
            </Form.Item>
            <Form.Item name={'content'}
                label={'文章内容'}>
                <TheQuill defaultValue = {content} setNewsContent={this.setNewsContent} />
            </Form.Item>
            <div className="p-text-align">
                <Space size="large">
                    <Button key="back" onClick={dialogCancel}>
                        取 消
                    </Button>
                    <Button type="primary" loading={btnLoading} htmlType="primary">
                        确 定
                    </Button>
                </Space>
            </div>
        </Form>
    }
}

export default Add;
